/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package at.tugraz.hidipic.model;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import org.hibernate.validator.constraints.Length;

/**
 *
 * @author mario
 */
@Entity
@Table(name="subproject")
public class SubProject implements Serializable {

    @Id
    @GeneratedValue
    private int id;
    @Length(min = 3, max = 50, message = "{projectname.length}")
    @Pattern(regexp = "[a-zA-Z0-9]+", message = "{projectname.regexp}")
    @NotNull
    private String name;
    @Length(min = 0, max = 255, message = "{description.length}")
    @NotNull
    private String description;
    @Temporal(TemporalType.TIMESTAMP)
    private Date creationDate;
    @ManyToOne
    @JoinColumn(name = "idProject")
    @NotNull
    private Project parent;
    @ManyToOne
    @JoinColumn(name = "idCreator")
    private User creator;
    @OneToMany(mappedBy = "subProject")
    private Set<Comment> comments;
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "researchersinsubproject")
    private Set<User> researchers;
    @OneToMany(mappedBy = "subProject")
    private Set<Result> results;
    @OneToMany(mappedBy = "subProject")
    private Set<Event> events;
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "shareduserlists")
    private Set<User> sharedUserList;

    public Set<User> getSharedUserList() {
        return sharedUserList;
    }

    public void setSharedUserList(Set<User> sharedUserList) {
        this.sharedUserList = sharedUserList;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Set<Comment> getComments() {
        return comments;
    }

    public void setComments(Set<Comment> comments) {
        this.comments = comments;
    }

    public Date getCreationDate() {
        return creationDate;
    }

    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

    public User getCreator() {
        return creator;
    }

    public void setCreator(User creator) {
        this.creator = creator;
    }

    public Set<Event> getEvents() {
        return events;
    }

    public void setEvents(Set<Event> events) {
        this.events = events;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Project getParent() {
        return parent;
    }

    public void setParent(Project parent) {
        this.parent = parent;
    }

    public Set<User> getResearchers() {
        return researchers;
    }

    public void setResearchers(Set<User> researchers) {
        this.researchers = researchers;
    }

    public Set<Result> getResults() {
        return results;
    }

    public void setResults(Set<Result> results) {
        this.results = results;
    }

    @Override
    public boolean equals(Object obj) {
        Integer equalsId = this.id;
        if (obj instanceof SubProject) {
            return equalsId.equals(((SubProject) obj).getId());
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        Integer hashId = this.id;
        return hashId.hashCode();
    }
}
